//
//  LoginNomalView.swift
//  Swift_WeiBo
//
//  Created by dajie on 15/8/21.
//  Copyright (c) 2015年 dajie. All rights reserved.
//

import UIKit

enum EmptyLoginType : Int
{
    case EmptyLoginType_Home = 0  //  首页未登录空页面
    case EmptyLoginType_Message  //  消息未登录空页面
    case EmptyLoginType_Discover  //  发现未登录空页面
    case EmptyLoginType_Profile  //  我未登录空页面
}

@objc protocol LoginNomalViewDelegate : NSObjectProtocol{
    
    /**
    点击登录和注册按钮的协议
    
    :param: loginView 类本身
    :param: button    点击的哪一个按钮
    */
    optional func loginNormalViewLogin(loginView loginView : LoginNomalView?, button : UIButton?)
    optional func loginNormalViewregist(loginView loginView : LoginNomalView?, button : UIButton?)
}

class LoginNomalView: UIView {
    
    @IBOutlet weak var bigImageView: UIImageView!
    @IBOutlet weak var centerImageView: UIImageView!
    @IBOutlet weak var shadowImageView: UIImageView!
    weak var loginDalegate : LoginNomalViewDelegate?  //  设置代理
    
//MARK: 重写set方法来改变图片的值
    var stauts : EmptyLoginType?{
        willSet(newStepValue)  //  didSet是oldValue
        {
            //  注意，如果是传入的是Int类型，则 EmptyLoginType(rawValue: newStepValue!) 转化一下
            if let type = newStepValue
            {
                switch type
                {
                    case .EmptyLoginType_Home:
                        shadowImageView.hidden = false
                        setEmptyView(centerImage: "visitordiscover_feed_image_house", bigImage: "visitordiscover_feed_image_smallicon")
                            print("EmptyLoginType_Home")
                        ExcuteAnimat()
                    
                    case .EmptyLoginType_Message:
                        setEmptyView(centerImage: "", bigImage: "visitordiscover_image_message")
                        print("EmptyLoginType_Message")
                    
                    case .EmptyLoginType_Discover:
                        setEmptyView(centerImage: "", bigImage: "visitordiscover_feed_image_smallicon")
                            print("EmptyLoginType_Discover")

                    case .EmptyLoginType_Profile:
                        setEmptyView(centerImage: "", bigImage: "visitordiscover_image_profile")
                            print("EmptyLoginType_Profile")
                    
                    
                    default:
                        print("default")
                }
//                println(type.hashValue)
            }
        }
    }
    
    override func awakeFromNib()
    {

    }
    
// MARK: - 按钮点击事件
    @IBAction func loginBtnClick(sender: UIButton)
    {
        loginDalegate?.loginNormalViewLogin!(loginView: self, button: sender)
    }
    
    @IBAction func regist(sender: UIButton)
    {
        loginDalegate?.loginNormalViewregist!(loginView: self, button: sender)
       
    }
    
//  MARK: - 根据不同的枚举值设置不同的空页面
    func setEmptyView(centerImage centerImage : String, bigImage : String)
    {
        centerImageView!.image = UIImage(named: centerImage)
        bigImageView!.image = UIImage(named: bigImage)
    }
    
//  MARK: - 执行动画
    func ExcuteAnimat()
    {
        let baseAnimat = CABasicAnimation(keyPath: "transform.rotation.z") as CABasicAnimation
        baseAnimat.fromValue = 0
        baseAnimat.toValue = M_2_PI
        baseAnimat.duration = 7
        baseAnimat.repeatCount = MAXFLOAT
        
        bigImageView.layer .addAnimation(baseAnimat, forKey: nil)
    }
}
